/**   
 * Copyright 2011 COMERE Harold
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package etrl.geometry;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * \class IndexArray
 * \brief Storage class for geometry indice
 * @author harold
 *
 */
public class IndexArray
{
	/**
	 * Index list
	 */
	private ArrayList <Integer> _indice;
	
	/**
	 * \brief Initializes an empty index array
	 */
	public IndexArray()
	{
		_indice = new ArrayList <Integer>();
	}
	
	/**
	 * \brief Adds a new index.
	 * @param[in] index Index to add.
	 */
	public void push_back(Integer index)
	{
		_indice.add(index);
	}
	
	/**
	 * \brief Clears all indice in the array.
	 */
	public void clear()
	{
		_indice.clear();
	}
	
	/**
	 * \brief Gets the index array as int array, ready to send to webgl.
	 * @return Index array as int[]
	 */
	public int[] toIntArray()
	{
		int[] array = new int[_indice.size()];
		
		
		int i = 0;
		for(Iterator <Integer> it = _indice.iterator(); it.hasNext();)
		{
			Integer index = it.next();
			array[i] = index;
			++i;
		}
		
		return array;
	}

	/**
	 * \brief Gets the number of index in the array
	 * @return Index count
	 */
	public int size()
	{
		return _indice.size();
	}
	
	/**
	 * \brief Gets the index list. 
	 * @return Index list
	 */
	public ArrayList <Integer> getIndice()
	{
		return _indice;
	}
}
